Answer the following questions and complete the exercises in
RMarkdown. Please embed all of your code and push your final work to
your repository. Your final lab report should be organized, clean, and
run free from errors. Remember, you must remove the # for
the included code chunks to run. Be sure to add your name to the author
header above. For any included plots, make sure they are clearly
labeled. You are free to use any plot type that you feel best
communicates the results of your analysis.
Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!
library(tidyverse)
library(janitor)
library(here)
library(ggmap)
We will use two separate data sets for this homework.
The first data set represent sightings of grizzly bears (Ursos arctos) in Alaska.
The second data set is from Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.
Load the grizzly data and evaluate its
structure.
grizzly <- read.csv("data/bear-sightings.csv")
glimpse(grizzly)
## Rows: 494
## Columns: 3
## $ bear.id <int> 7, 57, 69, 75, 104, 108, 115, 116, 125, 135, 137, 162, 185, …
## $ longitude <dbl> -148.9560, -152.6228, -144.9374, -152.8485, -143.2948, -149.…
## $ latitude <dbl> 62.65822, 58.35064, 62.38227, 59.90122, 61.07311, 62.91605, …
grizzly %>%
select(latitude, longitude) %>%
summary()
## latitude longitude
## Min. :55.02 Min. :-166.2
## 1st Qu.:58.13 1st Qu.:-154.2
## Median :60.97 Median :-151.0
## Mean :61.41 Mean :-149.1
## 3rd Qu.:64.13 3rd Qu.:-145.6
## Max. :70.37 Max. :-131.3
bbox <- make_bbox(c(-166.2, -131.3), c(55.02, 70.37), f=0.05)
stamen in a terrain style projection
and display the map.map1 <- get_map(bbox, maptype = "terrain", source = "stamen")
## ℹ Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
ggmap(map1)
ggmap(map1)+
geom_point(data=grizzly, aes(longitude, latitude), size = 1)+
labs(title = "Grizzly Bear Sighting Locations in Alaska",
x= "Longitude",
y="Latiude")
Let’s switch to the wolves data. Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.
wolves <- read.csv("data/wolves_data/wolves_dataset.csv")
glimpse(wolves)
## Rows: 1,986
## Columns: 23
## $ pop <chr> "AK.PEN", "AK.PEN", "AK.PEN", "AK.PEN", "AK.PEN", "…
## $ year <int> 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 200…
## $ age.cat <chr> "S", "S", "A", "S", "A", "A", "A", "P", "S", "P", "…
## $ sex <chr> "F", "M", "F", "M", "M", "M", "F", "M", "F", "M", "…
## $ color <chr> "G", "G", "G", "B", "B", "G", "G", "G", "G", "G", "…
## $ lat <dbl> 57.03983, 57.03983, 57.03983, 57.03983, 57.03983, 5…
## $ long <dbl> -157.8427, -157.8427, -157.8427, -157.8427, -157.84…
## $ habitat <dbl> 254.08, 254.08, 254.08, 254.08, 254.08, 254.08, 254…
## $ human <dbl> 10.42, 10.42, 10.42, 10.42, 10.42, 10.42, 10.42, 10…
## $ pop.density <dbl> 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, …
## $ pack.size <dbl> 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.7…
## $ standard.habitat <dbl> -1.6339, -1.6339, -1.6339, -1.6339, -1.6339, -1.633…
## $ standard.human <dbl> -0.9784, -0.9784, -0.9784, -0.9784, -0.9784, -0.978…
## $ standard.pop <dbl> -0.6827, -0.6827, -0.6827, -0.6827, -0.6827, -0.682…
## $ standard.packsize <dbl> 1.3157, 1.3157, 1.3157, 1.3157, 1.3157, 1.3157, 1.3…
## $ standard.latitude <dbl> 0.7214, 0.7214, 0.7214, 0.7214, 0.7214, 0.7214, 0.7…
## $ standard.longitude <dbl> -2.1441, -2.1441, -2.1441, -2.1441, -2.1441, -2.144…
## $ cav.binary <int> 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
## $ cdv.binary <int> 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ cpv.binary <int> 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, …
## $ chv.binary <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, …
## $ neo.binary <int> NA, NA, NA, 0, 0, NA, NA, 1, 0, 1, NA, 0, NA, NA, N…
## $ toxo.binary <int> NA, NA, NA, 1, 0, NA, NA, 1, 0, 0, NA, 0, NA, NA, N…
length(unique(wolves$pop))
## [1] 17
unique(wolves$pop)
## [1] "AK.PEN" "BAN.JAS" "BC" "DENALI" "ELLES" "GTNP" "INT.AK"
## [8] "MEXICAN" "MI" "MT" "N.NWT" "ONT" "SE.AK" "SNF"
## [15] "SS.NWT" "YNP" "YUCH"
lower_us <- wolves%>%
filter(pop != "AK.PEN" & pop != "INT.AK" & pop != "SE.AK")
head(lower_us)
## pop year age.cat sex color lat long habitat human
## 1 BAN.JAS 2001 A F B 52.19775 -117.0543 18553.18 1144.68
## 2 BAN.JAS 2003 A F B 52.19775 -117.0543 18553.18 1144.68
## 3 BAN.JAS 2001 A F B 52.19775 -117.0543 18553.18 1144.68
## 4 BAN.JAS 2003 A F B 52.19775 -117.0543 18553.18 1144.68
## 5 BAN.JAS 2005 S M B 52.19775 -117.0543 18553.18 1144.68
## 6 BAN.JAS 2001 A F G 52.19775 -117.0543 18553.18 1144.68
## pop.density pack.size standard.habitat standard.human standard.pop
## 1 8.85 9.56 0.7667 -0.4298 -0.5925
## 2 8.85 9.56 0.7667 -0.4298 -0.5925
## 3 8.85 9.56 0.7667 -0.4298 -0.5925
## 4 8.85 9.56 0.7667 -0.4298 -0.5925
## 5 8.85 9.56 0.7667 -0.4298 -0.5925
## 6 8.85 9.56 0.7667 -0.4298 -0.5925
## standard.packsize standard.latitude standard.longitude cav.binary cdv.binary
## 1 1.7742 0.1928 -0.0102 NA 1
## 2 1.7742 0.1928 -0.0102 NA 1
## 3 1.7742 0.1928 -0.0102 NA 1
## 4 1.7742 0.1928 -0.0102 NA 1
## 5 1.7742 0.1928 -0.0102 NA 0
## 6 1.7742 0.1928 -0.0102 NA 1
## cpv.binary chv.binary neo.binary toxo.binary
## 1 1 NA NA NA
## 2 1 NA NA NA
## 3 1 NA NA NA
## 4 1 NA NA NA
## 5 1 NA NA NA
## 6 1 NA NA NA
lower_us%>%
select(lat, long)%>%
summary()
## lat long
## Min. :33.89 Min. :-151.06
## 1st Qu.:44.60 1st Qu.:-117.05
## Median :46.83 Median :-110.99
## Mean :49.77 Mean :-113.97
## 3rd Qu.:57.89 3rd Qu.:-110.55
## Max. :80.50 Max. : -82.42
bbox <- make_bbox(c(-151.06, -82.42), c(33.89, 80.50), f=0.05)
stamen in a terrain-lines
projection and display the map.map1 <- get_map(bbox, maptype = "terrain", source = "stamen")
## ℹ Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
ggmap(map1)
ggmap(map1)+
geom_point(data=lower_us, aes(long, lat), size = 1)+
labs(title = "Wolf Observation Locations",
x= "Longitude",
y="Latiude")
fill and color by population.ggmap(map1)+
geom_point(data=lower_us, aes(long, lat, color=pop), size = 1)+
labs(title = "Wolf Observation Locations",
x= "Longitude",
y="Latiude")
Please be sure that you check the keep md file in the
knit preferences.